
//报警联动窗口
AlarmVideoWindow = {};

AlarmVideoWindow.isOpening = false;
AlarmVideoWindow.checkWindowInterval = 1;//15秒检查一次窗口的播放状态，如果某一车辆播放超过设定的时间，自动关闭;
AlarmVideoWindow.playTimeSpan = 60;//默认报警视频一分钟后关闭;
AlarmVideoWindow.timerName = "alarmVideoPlayTimer";
AlarmVideoWindow.title = "报警视频联动";
AlarmVideoWindow.startPlayTime = null;

AlarmVideoWindow.getIFrame= function()
{
    return $('#alarmVideoWindowIframe')[0];
}

AlarmVideoWindow.init = function()
{
    var url = globalConfig.webPath + "/videoCommand/viewRealTimeVideo.action?popupWindow=true";
    var width = 700;
    var height = 380;
    var title = "视频监控窗口";
//$('#commandIframe')[0].src = "about:blank";
    //清空iframe的内容,避免缓存
    AlarmVideoWindow.getIFrame().contentWindow.document.body.innerText = "";
    AlarmVideoWindow.getIFrame().src=url;
    $('#alarmVideoWindow').dialog({
        width:width,
        height:height,
        title:title,
        minimizable: true,
        modal:false,
        //closed:true,
        onBeforeClose:onAlarmVideoWindowBeforeClose
    });
    AlarmVideoWindow.close();

}

AlarmVideoWindow.checkVideoPlayTime = function()
{
    if(this.startPlayTime == null)
        return;
    var now = new Date();
    var sec = (now - this.startPlayTime) / 1000;
    var remain = Math.floor(this.playTimeSpan - sec);
    var tempTitle = this.title + " 将在" + remain + "秒后自动关闭";
    $('#alarmVideoWindow').panel({title:tempTitle});

    if(sec >= this.playTimeSpan)
    {
        //$('#alarmVideoWindow').window('close');
        AlarmVideoWindow.close();
    }
}

function onAlarmVideoWindowBeforeClose()
{
    var iframeWindow = AlarmVideoWindow.getIFrame();
    if(iframeWindow && iframeWindow.contentWindow.onWindowBeforeClose)
         iframeWindow.contentWindow.onWindowBeforeClose();

    AlarmVideoWindow.close();
    return false;
}

AlarmVideoWindow.close=function()
{
    $('#alarmVideoWindow').parent().css("z-index","-100");
    $('.window-shadow').hide();
    AlarmVideoWindow.startPlayTime = null;
    $('body').stopTime (this.timerName);
}


AlarmVideoWindow.open=function()
{
    $('#alarmVideoWindow').parent().css("z-index","9999");
    $('.window-shadow').hide();
    var strInterval = this.checkWindowInterval + 's';
    var me = this;
    $('body').everyTime(strInterval, this.timerName,function(){
        me.checkVideoPlayTime();//更新模式
    });
}


/**
 * 在弹出窗口的基础上继续弹出子窗口
 */
AlarmVideoWindow.viewRealTimeVideo = function(vehicleId, plateNo, simNo, title, channels){

    this.title = title;
    title += " 将在" + this.playTimeSpan + "秒后自动关闭";
    $('#alarmVideoWindow').panel({title:title});
    //$('#alarmVideoWindow').window('open');

    AlarmVideoWindow.open();

    AlarmVideoWindow.getIFrame().contentWindow.playAlarmVideo(vehicleId, plateNo, simNo,channels);

    this.startPlayTime = new Date();


}


